package ebcs.database.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ebcs.database.bean.BsNeedInfor;
import ebcs.database.bean.BsNeedInforData;
import ebcs.database.bean.BsNeedInforExample;
import ebcs.database.bean.BsNeedTime;
import ebcs.database.bean.BsUserInfor;
import ebcs.database.bean.BsUserNeedRel;
import ebcs.database.bean.BsUserNeedRelExample;
import ebcs.database.bean.BsUserNeedRelExample.Criteria;
import ebcs.database.bean.RpUserReportBean;
import ebcs.database.bean.RpUserTaskNeedBean;
import ebcs.database.mybatis.dao.BsNeedInforMapper;
import ebcs.database.mybatis.dao.BsNeedInforMapperSelf;
import ebcs.database.mybatis.dao.BsUserInforMapper;
import ebcs.database.mybatis.dao.BsUserNeedRelMapper;
import ebcs.database.mybatis.dao.RpUserReportMapper;
import ebcs.database.mybatis.dao.RpUserTaskNeedMapper;
import ebcs.database.service.BsUserNeedServiceImp;
import ebcs.scan.common.utils.StringUtil;

@Service
public class BsUserNeedServiceImpl implements BsUserNeedServiceImp
{
	@Autowired
	private BsUserNeedRelMapper userNeedRelDao;
	 
	@Autowired
	private RpUserReportMapper reportDao;
	
	@Autowired
	private RpUserTaskNeedMapper taskDao;
	
	@Autowired
	private BsNeedInforMapper needDao;
	
	@Autowired
	private BsUserInforMapper userDao;
	
	@Autowired
	private BsNeedInforMapperSelf needSelfDao;
	
	@Override
	public boolean regUserNeedRel(BsUserNeedRel record) {
		int i = userNeedRelDao.insert(record);
		if(i>0){
			return true;
		}
		return false;
	}
	//
	@Override
	public List<RpUserReportBean> searchUserNeedInfor(RpUserReportBean record) {		
		return reportDao.selectReport(record);
	}  
	//
	@Override
	public List<RpUserReportBean> selectReportCount(RpUserReportBean record) {		
		return reportDao.selectReportCount(record);
 	}
	@Override
	public List<RpUserTaskNeedBean> selectTaskNeedList(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectTaskNeedList(condition);
		return rsList;
	}
	
	@Override
	public List<RpUserTaskNeedBean> selectNoTaskNeedList(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectNoTaskNeedList(condition);
		return rsList;
	}
	@Override
	public int selectUserTaskTime(RpUserTaskNeedBean condition) {
		return taskDao.selectUserTaskTime(condition);
	}
	@Override
	public int deleteUserNeedInfor(String rouid) {
		BsUserNeedRelExample example = new BsUserNeedRelExample();
		Criteria criteria = example.createCriteria();
		criteria.andRouidEqualTo(rouid); 
		return this.userNeedRelDao.deleteByExample(example);
	} 
  
	@Override
	public int addNeedInfor(BsNeedInfor record) { 
		return this.needDao.insert(record);
	}
	@Override
	public List<BsNeedInfor> selectNeedInforByNeedNoAndTeamNo(BsNeedInfor record) {
		BsNeedInforExample example = new BsNeedInforExample();
		ebcs.database.bean.BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andNeedNoEqualTo(record.getNeedNo());
		criteria.andProTeamNoEqualTo(record.getProTeamNo());		
		return this.needDao.selectByExample(example);
 	}
	@Override
	public List<RpUserTaskNeedBean> selectTaskNeedListByTeamNo(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectTaskNeedListByTeamNo(condition);
		return rsList;
	}
	@Override
	public List<RpUserTaskNeedBean> selectTaskNeedListByGroupNo(RpUserTaskNeedBean condition) {
		List<RpUserTaskNeedBean> rsList = taskDao.selectTaskNeedListByGroupNo(condition);
		return rsList;
	}
	@Override
	public List<RpUserReportBean> searchUserHistoryNeedInfor(RpUserReportBean reportConditon) {
		
		return reportDao.selectHistoryNeed(reportConditon);
	}
	
	
	@Override
	public int updateNeedInforById(BsNeedInfor need) {
		BsNeedInforExample example = new BsNeedInforExample();
		BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andRouidEqualTo(need.getRouid());		
		return this.needDao.updateByExample(need, example);
	}
	
	@Override
	public int updateNeedNoRelByNeedId(BsNeedInfor bean) {
	 
 		return this.needSelfDao.updateNeedNoRelByNeedId( bean);
	}
	@Override
	public List<BsNeedInfor> selectNeedInforList(BsNeedInfor need) {
		
		BsNeedInforExample example = new BsNeedInforExample();
		BsNeedInforExample.Criteria criteria = example.createCriteria();
		criteria.andProTeamNoEqualTo(need.getProTeamNo());
		if(StringUtil.isNotEmpty(need.getNeedName())){
			criteria.andNeedNoLike(need.getNeedName());
		}
		if(StringUtil.isNotEmpty(need.getNeedName())){
			BsNeedInforExample.Criteria orCriteria = example.createCriteria();
			orCriteria.andNeedNameLike(need.getNeedName());
			example.or(orCriteria);
		}
		
		return this.needDao.selectByExample(example);
		
	}
	@Override
	public List<BsNeedInfor> selectNeedInfor(BsNeedInfor need) {
		if (StringUtil.isEmpty(need.getCurrentPage())) {
			need.setStartRow("0");
			need.setEndRow(need.getPageSize()==null?"200":need.getPageSize());
		} else {
			need.setStartRow((Integer.parseInt(need.getCurrentPage()) - 1) * Integer.parseInt(need.getPageSize()) + "");
			need.setEndRow((Integer.parseInt(need.getCurrentPage())) * Integer.parseInt(need.getPageSize()) + "");
		}
		return this.needSelfDao.selectNeedInfor(need);
	}
	
	@Override
	public List<BsNeedTime> selectNeedTimeList(BsUserInfor user) {
		return this.needSelfDao.selectNeedTime(user) ;
	}
	@Override
	public int closeUserNeedRel(String rouid) {
		// TODO Auto-generated method stub
		return this.userNeedRelDao.closeUserNeedRel(rouid);
	}
	@Override
	public List<BsNeedInfor> selectNoPassNeedByRouid(String rouid) {
		return this.needDao.selectNoPassNeedByRouid(rouid);
	}
	@Override
	public int updateStateByRouid(String rouid, String state) {
		return this.needDao.updateStateByRouid(rouid, state);
	}
	@Override
	public List<BsNeedInforData> selectByBsNeedInforData(BsNeedInforData bsNeedInforData) {
		return this.needDao.selectByBsNeedInforData(bsNeedInforData);
	}
	@Override
	public int insertNeedInforData(List<BsNeedInforData> list) {
		// TODO Auto-generated method stub
		return this.needDao.insertNeedInforData(list);
	}
	@Override
	public int updateNeedInforDataByNeedNo(BsNeedInforData bsNeedInforData) {
		// TODO Auto-generated method stub
		return this.needDao.updateNeedInforDataByNeedNo(bsNeedInforData);
	}
	@Override
	public int deleteNeedInforData() {
		// TODO Auto-generated method stub
		return this.needDao.deleteNeedInforData();
	}
	@Override
	public List<BsNeedInfor> selectNeedInforDetail(BsNeedInfor need) {
		// TODO Auto-generated method stub
		return this.needSelfDao.selectNeedInforDetail(need);
	}
	@Override
	public int reStartUserNeedRel(String rouid) {
		// TODO Auto-generated method stub
		return this.userNeedRelDao.reStartUserNeedRel(rouid);
	}
	@Override
	public BsUserInfor getProTeamNo(String userNo) {
		// TODO Auto-generated method stub
		return this.userDao.getProTeamNo(userNo);
	}
	@Override
	public void updateNeedInfor(BsNeedInfor needInfor) {
		this.needDao.updateNeedInfor(needInfor);
	}

	@Override
	public List<BsUserNeedRel> selectByNeedId(String needId) {
		// TODO Auto-generated method stub
		return userNeedRelDao.selectByNeedId(needId);
	}
	@Override
	public boolean deleteInfor(String needId) {
		// TODO Auto-generated method stub
		return userNeedRelDao.deleteInfor(needId);
	}
	@Override
	public List<RpUserReportBean> seachReviewJob(RpUserReportBean reportConditon) {
		// TODO Auto-generated method stub
		return reportDao.seachReviewJob(reportConditon);
	}
	@Override
	public void updateReportStateByRouId(BsUserNeedRel bsUserNeedRel) {
		// TODO Auto-generated method stub
		userNeedRelDao.updateReportStateByRouId(bsUserNeedRel);
	}
 
 
}
